<?php

namespace app\api\controller;

use app\BaseController;
use think\facade\Request;
use think\facade\Cache;

class Base extends BaseController
{
    protected $middleware = ['api_check_token'];
    public $token;

    protected $notAuthRequestUrl = [
        'login/login',
        'home/index',
        'wx/callback',
        'wx/login',
        'wx/getwxurl',
        'tiktok/callback',
        'tiktok/newcallback',
        'tiktok/login',
        'wx/seraphlogin',
        'wx/officialaccountlogin',
        'topup/isopeniospay',
        'topup/appletconfig',
        'video/list',
    ];

    public function __construct()
    {
        $url = Request::controller() . '/' . Request::action();
        $requestUrl = strtolower($url);

        if (!in_array($requestUrl, $this->notAuthRequestUrl)) {
            $header = Request::header();
            $this->token = $header['token'];
        }
    }

    /**
     * 获取用户id
     * @return mixed
     */
    public function getUserID()
    {
        $header = Request::header();
        $redis = Cache::store('redis')->handler();
        $redis->select(8);
        return $redis->get($header['token']);
    }
}